package com.googlecode.spruce.domain;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "operating_system")
public class OperatingSystem implements Serializable
{
    /**
     * Serial ID
     */
    private static final long serialVersionUID = -4609327984238829706L;

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    @Column(name = "vendor")
    private String vendor;

    @Column(name = "product")
    private String product;

    @Column(name = "version")
    private String version;

    @OneToMany(mappedBy = "operatingSystem")
    private Set<Host> hosts;

    public int getId()
    {
        return id;
    }

    public void setId(final int id)
    {
        this.id = id;
    }

    /**
     * @return the vendor
     */
    public String getVendor()
    {
        return vendor;
    }

    /**
     * @param vendor
     *            the vendor to set
     */
    public void setVendor(final String vendor)
    {
        this.vendor = vendor;
    }

    /**
     * @return the product
     */
    public String getProduct()
    {
        return product;
    }

    /**
     * @param product
     *            the product to set
     */
    public void setProduct(final String product)
    {
        this.product = product;
    }

    /**
     * @return the version
     */
    public String getVersion()
    {
        return version;
    }

    /**
     * @param version
     *            the version to set
     */
    public void setVersion(final String version)
    {
        this.version = version;
    }

    public Set<Host> getHosts()
    {
        return hosts;
    }

    public void setHosts(final Set<Host> hosts)
    {
        this.hosts = hosts;
    }

    /**
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((product == null) ? 0 : product.hashCode());
        result = prime * result + ((vendor == null) ? 0 : vendor.hashCode());
        result = prime * result + ((version == null) ? 0 : version.hashCode());
        return result;
    }

    /**
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(final Object obj)
    {
        if (this == obj)
        {
            return true;
        }
        if (obj == null)
        {
            return false;
        }
        if (getClass() != obj.getClass())
        {
            return false;
        }
        OperatingSystem other = (OperatingSystem) obj;
        if (product == null)
        {
            if (other.product != null)
            {
                return false;
            }
        }
        else if (!product.equals(other.product))
        {
            return false;
        }
        if (vendor == null)
        {
            if (other.vendor != null)
            {
                return false;
            }
        }
        else if (!vendor.equals(other.vendor))
        {
            return false;
        }
        if (version == null)
        {
            if (other.version != null)
            {
                return false;
            }
        }
        else if (!version.equals(other.version))
        {
            return false;
        }
        return true;
    }

}
